#ifndef CPU_PROC_H
#define CPU_PROC_H

#include "data.h"
//#include "externals.h"

void CPU_Proc(struct Agent_Var* agent, int dir)
{
    pos_t op_start = agent->pc - sizeof(opcode_t);
    aid_t procAgent = READ_CODE(agent,aid_t);
    pos_t entry = READ_CODE(agent,pos_t);

    if(tavm_agents_v[procAgent].state == AS_WAITING)
    {
        tavm_agents_v[procAgent].state = AS_TAKEN;
        tavm_agents_v[procAgent].procAgent = SYS_GetAgentId(agent);
        tavm_agents_v[procAgent].pc = entry;
        agent->procAgent = procAgent;
        CPU_SendPort(agent,dir);
        agent->state = AS_RUNNING;
    }
    else
    {
        agent->state = AS_WAITING;
        agent->pc = op_start;
    }
    agent->procAgent = procAgent;
}

#endif


